package com.seek.inter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.seek.common.handler.SpringContextHolder;
import com.seek.constants.ApiParamsConstant;
import com.seek.model.dto.ResultInfo;
import com.seek.model.entity.TCrashInfo;
import com.seek.service.CrashInfoService;
import com.seek.util.DateUtil;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Transactional;

/**
 * app崩溃数据收集接口
 * Created by weh on 2017/7/22.
 */
public class CrashInter {

  private CrashInfoService crashInfoService = (CrashInfoService) SpringContextHolder
      .getBean("crashInfoService");

  public ResultInfo uploadCrashInfo(HttpServletRequest request, JSONObject reqJson)
      throws Exception {
    ResultInfo result = new ResultInfo();

    TCrashInfo crashInfo = new TCrashInfo();
    crashInfo.setVersionName(reqJson.getString(ApiParamsConstant.VER_NAME));
    crashInfo.setVersionCode(reqJson.getString(ApiParamsConstant.VER_CODE));
    crashInfo.setPageName(reqJson.getString(ApiParamsConstant.PAGE_NAME));
    crashInfo.setErrName(reqJson.getString(ApiParamsConstant.ERR_NAME));
    crashInfo.setErrType(reqJson.getString(ApiParamsConstant.ERR_TYPE));
    crashInfo.setErrDetail(reqJson.getString(ApiParamsConstant.ERR_DETAIL));
    crashInfo.setAppVersion(reqJson.getString(ApiParamsConstant.APP_VER));
    crashInfo.setOsVersion(reqJson.getString(ApiParamsConstant.OS_VER));
    crashInfo.setDeviceModel(reqJson.getString(ApiParamsConstant.DEVICE_MODEL));
    crashInfo.setDeviceId(reqJson.getString(ApiParamsConstant.DEVICE_ID));
    crashInfo.setNetworkType(reqJson.getString(ApiParamsConstant.NETWORK_TYPE));
    crashInfo.setChannelId(reqJson.getString(ApiParamsConstant.CHANNEL_ID));
    crashInfo.setMemoInfo(reqJson.getString(ApiParamsConstant.MEMO_INFO));
    crashInfo.setCreateTime(new Date());
    crashInfo.setCrashUser(reqJson.getString(ApiParamsConstant.CRASH_USER));

    crashInfoService.save(crashInfo);
    result.setStatus(0);
    result.setMessage("操作成功");
    return result;
  }

}
